package com.hs.jhzd.service.message;

import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Service;

import com.hs.jhzd.config.MqCondition;
import com.hs.jhzd.entity.SystemNotice;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
@Conditional(MqCondition.class)
public class NoticeProducer implements MessageProducer {
  @Autowired
  private RabbitTemplate noticeRabbitTemplate;

  /*
   * (non-Javadoc)
   * 
   * @see com.newings.service.message.MessageProducer#sendMessage(java.lang.Object)
   */
  @Override
  public void sendMessage(Object object) {}

  /*
   * (non-Javadoc)
   * 
   * @see com.newings.service.message.MessageProducer#sendMessage(java.lang.String,
   * java.lang.Object)
   */
  @Override
  public void sendMessage(String routingKey, Object object) {
    if (object == null) {
      return;
    }
    SystemNotice notice = (SystemNotice) object;
    if (StringUtils.isBlank(notice.getOrder())) {
      return;
    }
    noticeRabbitTemplate.convertAndSend(routingKey, object);
    log.debug("发送通知消息：" + notice.toString() + " with routingKey:" + routingKey);
  }

}
